package com.itlong.cloud.intercept;

import com.itlong.cloud.annotation.LoggerInfo;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * <desc>
 *     一卡通日志拦截器
 * </desc>
 *
 * @createDate 2018/06/12
 */
@Aspect
@Component
public class LoggerInterceptor {

    /**
     * <desc>
     *     定义一个切入点
     * </desc>
     *
     * @author wangzhi
     * @createDate 2018/06/12
     */
    @Pointcut("execution(* com.itlong.cloud.controller..*.*(..))")
    public void excudeService(){}

    /**
     * <desc>
     *     一卡通日志打印
     * </desc>
     *
     * @param thisJoinPoint AOP接入点
     * @param loggerInfo 日志注解对象
     * @throws Exception
     * @author wangzhi
     * @createDate 2018/06/12
     */
    @After("excudeService() && @annotation(loggerInfo)")
    public void twiceAsOld(JoinPoint thisJoinPoint, LoggerInfo loggerInfo) {
        Logger logger = LoggerFactory.getLogger(thisJoinPoint.getThis().getClass());
        //logger.info(String.format("%s【%s】",thisJoinPoint.getSignature().getName(),loggerInfo.operateDesc()));
        System.err.println("已经输出到日志的内容：" + String.format("%s【%s】",thisJoinPoint.getSignature().getName(),loggerInfo.operateDesc()));
    }

}
